package com.cn.springcloudwechat.controller.base;

import com.cn.springcloudwechat.common.ajax.AjaxRes;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 异常处理controller
 * @author: Administrator
 * @create: 2018/7/20 15:31
 */

@ControllerAdvice
@ResponseBody
public class ExceptionController {

    @ExceptionHandler(Exception.class)
    public AjaxRes controllerException(Exception e){
        AjaxRes ajaxRes=new AjaxRes();
        ajaxRes.setFailMsg(e.getMessage());
        StackTraceElement[] st= e.getStackTrace();
        for (StackTraceElement s:st ) {
            System.out.println("className:"+s.getClassName()+",method："+s.getMethodName()+",linNumber："+s.getLineNumber()+",fileName："+s.getFileName());
        }
        e.printStackTrace();
        return ajaxRes;
    }


}
